home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hobby / gim_308.zip / GIM11E.DOC < prev    next >
Text File  |  1993-04-17  |  10KB  |  276 lines

  1.           CHAPTER 11     LISTS OF SIMILAR PERSONS, FAMILIES AND NOTES
  2.  
  3.                                       OR
  4.  
  5.           SEARCHING YOUR FOLDER FOR SPECIFIC INFORMATION
  6.  
  7.  
  8. PART E:  CONJUNCTIONS USED IN WHERE COMMANDS
  9.  
  10.           In this section we assume that you know what a WHERE command
  11.           is, how it's used, and what it's used for.  We also assume
  12.           that you know what operators and operands in WHERE commands
  13.           are, and how they are used.  If you haven't done so already,
  14.           review the first section in this chapter, which is entitled
  15.           "An Introduction with Basic Examples", and skim the sections
  16.           entitled "Operators Used in WHERE Commands" and "Operands
  17.           Used in WHERE Commands".
  18.  
  19. DEFINITION...
  20.  
  21.           DEFINITION:  A CONJUNCTION
  22.  
  23.           After reading those sections, you know how to make sense of
  24.           the following where commands:
  25.  
  26.           WHERE birth date is after 1950
  27.           WHERE birth date is before 1970
  28.  
  29.           But so far, we've kept quiet about how to search for dates
  30.           that are BETWEEN 1950 and 1970.  That is done by combining
  31.           these two expressions into a single WHERE command by using
  32.           the word AND, as follows:
  33.  
  34.           WHERE birth date is after 1950 AND birth date is before 1970
  35.  
  36.           The word "AND" is a conjunction.  GIM LISTS provides three
  37.           conjunctions:  AND, OR, and NOT.  This section explains how
  38.           to use these conjunctions in WHERE commands.
  39.  
  40. ATOMS...
  41.  
  42.           DEFINITION:  AN ATOM IN A WHERE COMMAND
  43.  
  44.           All of the following are examples of atoms:
  45.  
  46.           any place contains "Denmark"
  47.           full is "Abe Lincoln"
  48.           birth date is before 1964
  49.           general source note is missing
  50.           children gt 5
  51.           children le 7
  52.  
  53.           If you've read all of the GIM LISTS sections of this manual
  54.           up to this point, you've seen dozens of atoms.
  55.  
  56.           An atom is the smallest piece of a WHERE command that still
  57.           makes sense on its own.  It consists of a left-hand operand,
  58.           an operator, and most of the time, a right-hand operand.
  59.  
  60. COMBINING...
  61.  
  62.           COMBINING ATOMS TOGETHER
  63.  
  64.           Atoms can be combined in all sorts of ways, as you will see.
  65.  
  66.           For example, we could combine the first two atoms with an OR,
  67.           like this:
  68.  
  69.           WHERE any place contains "Denmark" OR full is "Abe Lincoln"
  70.  
  71.           Or we could combine the last two atoms with an AND, like this:
  72.  
  73.           WHERE children GT 5 AND children LE 7
  74.  
  75.           In fact, we can combine any number of atoms -- whatever they
  76.           are -- with ANDs and ORs and NOTs.
  77.  
  78. ABBREVIATIONS...
  79.  
  80.           If you've read the previous several sections of this manual,
  81.           you know what an atom is.  For the rest of this section, we
  82.           want to ignore the atoms and focus on the conjunctions.
  83.  
  84.           To help with this, we're going to represent atoms with double
  85.           lower case letters -- like aa, bb, cc, and so on. When you
  86.           see an abbreviation like "aa", you should realize that "aa"
  87.           means "any atom that you want to put here".  This will help
  88.           us to ignore the atoms in order to focus on the conjunctions.
  89.  
  90.           In other words, we won't talk about these WHERE commands:
  91.  
  92.           WHERE any place contains "Denmark" OR full is "Abe Lincoln"
  93.           WHERE children GT 5 AND children LE 7
  94.  
  95.           ... instead, we'll just refer to these:
  96.  
  97.           WHERE aa OR bb
  98.           WHERE cc AND dd
  99.  
  100.           That way we can talk about ANDs, ORs, and NOTs, without the
  101.           values of the atoms themselves distracting us from the
  102.           discussion of conjunctions.
  103.  
  104. PUTTING SOME OF THE PIECES TOGETHER...
  105.  
  106.           You can join as many atoms together as you want, just as long
  107.           as there is an AND or an OR between each of them.  For
  108.           example, any sequence like the following is perfectly legal:
  109.  
  110.           WHERE aa AND bb OR cc
  111.           WHERE aa OR bb AND cc AND dd
  112.           WHERE aa AND bb AND cc AND dd OR ee AND ff AND gg
  113.  
  114. PRECEDENCE PROBLEM...
  115.  
  116.           A PRECEDENCE PREDICAMENT
  117.  
  118.           Now, this brings up an interesting predicament.  Suppose for
  119.           a moment that "aa" is "blue eyes", "bb" is "blonde hair", and
  120.           "cc" is "female".
  121.  
  122.           If I'm searching for "aa AND bb", then I'm searching for
  123.           someone with blue eyes AND blonde hair, and anyone I pick has
  124.           to have both in order to be selected.
  125.  
  126.           On the other hand, if I'm searching for "aa OR bb", then I'm
  127.           searching for someone with EITHER blue eyes OR blonde hair;
  128.           it doesn't matter which -- I'll take someone with either one
  129.           or the other.
  130.  
  131.           But what do I mean if I say "aa AND bb OR cc"?  This could be
  132.           interpreted in either of two ways.
  133.  
  134.           On the one hand, it could mean that I'm looking for EITHER
  135.           someone with blonde hair and blue eyes OR someone who's
  136.           female.  That's one way to look at it, and it means that I'll
  137.           take any female, and I'll also take any blue-eyed, blonde-
  138.           haired male.
  139.  
  140.           On the other hand, it could mean that I'm looking for someone
  141.           with blue eyes, and who also EITHER has blonde hair OR is
  142.           female.  This is another way to look at it, and it means that
  143.           I'll take any blue-eyed, blonde-haired male, or any blue-eyed
  144.           female.
  145.  
  146.           This confusion arises from a problem that is solved by
  147.           defining what's called "precedence".  In other words, there
  148.           are "rules of precedence" that govern how GIM LISTS should
  149.           resolve ambiguous situations like this one.
  150.  
  151. PRECEDENCE SOLUTION...
  152.  
  153.           THE PRECEDENCE PREDICAMENT SOLVED
  154.  
  155.           The simplest of these "rules of precedence" is this:  all
  156.           other things being equal, AND takes precedence over OR.
  157.           (If you are a programmer, this rule comes as no surprise.)
  158.  
  159.           As a result, WHERE aa AND bb OR cc, from our example above,
  160.           should be thought of as:
  161.  
  162.           WHERE      aa AND bb     OR     cc
  163.  
  164.           ... rather than:
  165.  
  166.           WHERE      aa     AND     bb OR cc
  167.  
  168. PARENTHESIS...
  169.  
  170.           PARENTHESIS PRECEDENCE
  171.  
  172.           Now, if that's not what we mean, we can override the rules of
  173.           precedence by using parentheses.  We can surround two or more
  174.           atoms and their conjunctions with parentheses.  GIM LISTS
  175.           will evaluate everything inside parentheses before evaluating
  176.           anything outside of them.  (Again, to a programmer, this rule
  177.           comes as no surprise.)
  178.  
  179.           Therefore, if we really mean to say:
  180.  
  181.           WHERE      aa     AND     bb OR cc
  182.  
  183.           ... we can say this:
  184.  
  185.           WHERE aa AND (bb OR cc)
  186.  
  187.  
  188.  
  189.           AN EXAMPLE OF PARENTHESES
  190.  
  191.           As another example, consider the following:
  192.  
  193.           WHERE aa AND bb OR cc AND dd AND ee OR ff AND gg
  194.  
  195.           Because all of the ANDs are grouped together first, GIM LISTS
  196.           looks at this WHERE command and interprets it like this:
  197.  
  198.           WHERE aa AND bb
  199.  
  200.                    OR
  201.  
  202.                 cc AND dd AND ee
  203.  
  204.                    OR
  205.  
  206.                 ff AND gg
  207.  
  208.           But you can change this with parentheses.  For example, by
  209.           adding parentheses to our example, like this:
  210.  
  211.           WHERE aa AND ((bb OR cc) AND dd) AND (ee OR ff) AND gg
  212.  
  213.           ... then we instruct GIM LISTS to interpret this as follows:
  214.  
  215.           WHERE aa
  216.  
  217.                 AND
  218.  
  219.                 bb OR cc     AND     dd
  220.  
  221.                 AND
  222.  
  223.                 ee OR ff
  224.  
  225.                 AND
  226.  
  227.                 gg
  228.  
  229.           Study this for a while, and you'll see what I mean.  The use
  230.           of parentheses can get awfully intricate awfully fast, so
  231.           it's usually best to keep your WHERE commands as simple as
  232.           possible, just for your own sake.  But bear in mind that GIM
  233.           LISTS can keep up with as many sets of parentheses as you can
  234.           dish out, which can be useful and reassuring in those cases
  235.           where you need your WHERE commands to be intricate.
  236.  
  237. NOT...
  238.  
  239.           THE NOT MODIFIER
  240.  
  241.           Any place where you can put an AND or an OR, you can put an
  242.           AND NOT or an OR NOT.  So for example, you can say:
  243.  
  244.           WHERE aa AND NOT bb
  245.  
  246.           or
  247.  
  248.           WHERE aa AND bb OR NOT cc
  249.  
  250.           or
  251.  
  252.           WHERE aa AND NOT (bb AND cc)
  253.  
  254.           Doing so means what you think it means.  If "aa" is "blue
  255.           eyes" and "bb" is "blonde hair", then "aa AND NOT bb" means
  256.           "anybody who has blue eyes but who also DOESN'T have blonde
  257.           hair."  (Hint:  if you find yourself trying to use the word
  258.           "BUT" in a where clause, use "AND NOT" instead.)
  259.  
  260.           NOT may also be used by itself, without AND and OR, but this
  261.           usage is somewhat rare.  For example, you can say:
  262.  
  263.           WHERE NOT aa
  264.  
  265.           ... as for example:
  266.  
  267.           WHERE NOT surname contains "Smith"
  268.  
  269.           ... but this simply means:
  270.  
  271.           WHERE surname doesn't contain "Smith"
  272.  
  273.           Therefore, although NOT may be used by itself, there are
  274.           almost always other ways to say the same thing.
  275.  
  276.